import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router';

import Layout from '../layout/index.vue';
import DocPage from '../views/doc-page/index.vue';
import {delay} from "@/utils/delay";
import {events} from "@/utils/event";

const routes: Array<RouteRecordRaw> = [
  {
    name: 'Home',
    path: '/',
    redirect: '/components/input'
  },
  {
    name: 'Components',
    path:'/components',
    component: Layout,
    children: [
      {
        name:'input',
        path:'input',
        component: DocPage
      },
      {
        name:'button',
        path:'button',
        component: DocPage
      }
    ]
  },
  {
    name: 'Overview',
    path:'/overview',
    component: Layout,
    children: [
      {
        name:'theme',
        path:'theme/index.vue',
        component: DocPage
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.afterEach(async (to,from) => {
  await delay(200);
  events.emit('page-ready');
});

export default router
